home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pveditor.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-05  |  15.6 KB  |  433 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVEDITOR.H                           |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Text editor interface                |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. void __init_editors( void );
  16.  
  17. #ifndef _PVEDITOR_H
  18. #define _PVEDITOR_H
  19.  
  20. #define cxEDITOR          1        //editor context
  21.  
  22. #define MAX_LINE_LENGTH 256        //max displayable line
  23.  
  24. //EDITOR SETUP
  25. #define efOVERWRITE         0x0001 //editors work in overwrite mode
  26. #define efAUTO_INDENT       0x0002 //editors work in auto indent mode
  27. #define efCASE_SENSITIVE    0x0004 //serach/replace is case sensitive
  28. #define efWHOLE_WORDS_ONLY  0x0008 //search/replace matches whole words only
  29. #define efPROMPT_ON_REPLACE 0x0010 //replace shoud prompt on each replacement
  30. #define efREPLACE_ALL       0x0020 //auto replace all occurences
  31. #define efDO_REPLACE        0x0040 //now replacing
  32. #define efBACKUP_FILES      0x0080 //backup files on save
  33. #define efHARD_TABS         0x0100 //tabs or spaces
  34.  
  35. //EDITOR BOOLEANS
  36. #define ebDIRTY             0x0001
  37. #define ebMODIFIED          0x0002
  38. #define ebSELECTING         0x0004
  39. #define ebCAN_GROW          0x0008
  40. #define ebCAN_UNDO          0x0010
  41. #define ebDISPOSE_BUFFER    0x0020
  42. #ifdef SYNTAXHILIGHT
  43. #define ebSYNTAX_HILIGHT   0x0040
  44. #endif
  45.  
  46. #ifdef SYNTAXHILIGHT
  47.  
  48. #ifdef CPPHILIGHT
  49. #define syCPP             1
  50. //CPP SYNTAX HILIGHTING COLOR INDEXES
  51. #define cppWHITE          0
  52. #define cppCOMMENTS       1
  53. #define cppRESERVED_WORDS 2
  54. #define cppIDENTIFIERS    3
  55. #define cppSYMBOLS        4
  56. #define cppSTRINGS        5
  57. #define cppNUMBERS        6
  58. #define cppPREPROCESSOR   7
  59. #endif
  60.  
  61. #ifdef ASMHILIGHT
  62. #define syASM             2
  63. //ASM SYNTAX HILIGHTING COLOR INDEXES
  64. #define asmWHITE          0
  65. #define asmCOMMENTS       1
  66. #define asmRESERVED_WORDS 2
  67. #define asmIDENTIFIERS    3
  68. #define asmSYMBOLS        4
  69. #define asmSTRINGS        5
  70. #define asmDECIMALS       6
  71. #define asmHEXADECIMALS   7
  72. #define asmBINARIES       8
  73. #endif
  74.  
  75. #ifdef A51HILIGHT
  76. #define syA51             3
  77. //A51 SYNTAX HILIGHTING COLOR INDEXES
  78. #define a51WHITE          0
  79. #define a51COMMENTS       1
  80. #define a51RESERVED_WORDS 2
  81. #define a51IDENTIFIERS    3
  82. #define a51SYMBOLS        4
  83. #define a51STRINGS        5
  84. #define a51DECIMALS       6
  85. #define a51HEXADECIMALS   7
  86. #define a51BINARIES       8
  87. #endif
  88.  
  89. #endif //SYNTAXHILIGHT
  90.  
  91. //EDITOR COMMANDS
  92. #define cmeINDENT          cmUSER50 //indent marked block by one column
  93. #define cmeUNINDENT        cmUSER51 //unindent marked block by one column
  94. #define cmeCHAR_LEFT       cmUSER52 //move cursor one character to the left
  95. #define cmeCHAR_RIGHT      cmUSER53 //move cursor one character to the right
  96. #define cmeWORD_LEFT       cmUSER54 //move cursor one word to the left
  97. #define cmeWORD_RIGHT      cmUSER55 //move cursor one word to the right
  98. #define cmeLINE_START      cmUSER56 //move cursor to start of the line
  99. #define cmeLINE_END        cmUSER57 //move cursor to end of the line
  100.  
  101. //WARNING: multiply lines start!
  102. #define cmeLINE_UP         cmUSER58 //move cursor to the previous line
  103. #define cmeLINE_DOWN       cmUSER59 //move cursor to the next line
  104. #define cmePAGE_UP         cmUSER60 //move cursor one page up
  105. #define cmePAGE_DOWN       cmUSER61 //move cursor one page down
  106. #define cmeTEXT_START      cmUSER62 //move cursor to top of the file
  107. #define cmeTEXT_END        cmUSER63 //move cursor to bottom of the file
  108. #define cmeSCREEN_TOP      cmUSER64 //move cursor to top visible line
  109. #define cmeSCREEN_BOTTOM   cmUSER65 //move cursor to bottom visible line
  110. #define cmeSCROLL_UP       cmUSER66 //scroll text up
  111. #define cmeSCROLL_DOWN     cmUSER67 //scroll text down
  112. #define cmeTAB             cmUSER68 //tab pressed
  113. #define cmeNEW_LINE        cmUSER69 //cr
  114. //WARNING: multiply lines end!
  115.  
  116. #define cmeBACK_SPACE      cmUSER70 //delete previous character
  117. #define cmeDEL_CHAR        cmUSER71 //del current character
  118. #define cmeDEL_WORD        cmUSER72 //del to the end of the current word
  119. #define cmeDEL_START       cmUSER73 //del to start of the line
  120. #define cmeDEL_END         cmUSER74 //del to end of the line
  121. #define cmeDEL_LINE        cmUSER75 //del current line
  122. #define cmeINS_MODE        cmUSER76 //toggle ins mode
  123. #define cmeSTART_SELECT    cmUSER77 //select mode on
  124. #define cmeHIDE_SELECT     cmUSER78 //hide selection (Ctrl-K H)
  125. #define cmeINDENT_MODE     cmUSER79 //toggle auto indent mode
  126. #define cmeMARK0           cmUSER80
  127. #define cmeMARK1           cmUSER81
  128. #define cmeMARK2           cmUSER82
  129. #define cmeMARK3           cmUSER83
  130. #define cmeMARK4           cmUSER84
  131. #define cmeMARK5           cmUSER85
  132. #define cmeMARK6           cmUSER86
  133. #define cmeMARK7           cmUSER87
  134. #define cmeMARK8           cmUSER88
  135. #define cmeMARK9           cmUSER89
  136. #define cmeGMARK0          cmUSER90
  137. #define cmeGMARK1          cmUSER91
  138. #define cmeGMARK2          cmUSER92
  139. #define cmeGMARK3          cmUSER93
  140. #define cmeGMARK4          cmUSER94
  141. #define cmeGMARK5          cmUSER95
  142. #define cmeGMARK6          cmUSER96
  143. #define cmeGMARK7          cmUSER97
  144. #define cmeGMARK8          cmUSER98
  145. #define cmeGMARK9          cmUSER99
  146. #define cmeFIND            0xF0     //find dialog
  147. #define cmeREPLACE         0xF1     //replace dialog
  148. #define cmeSEARCH_AGAIN    0xF2     //repeat last search/replace
  149. #define cmeGOTO_LINE       0xF3     //goto line number dialog
  150. #define cmeEDITOR_OPEN     (cmVALID-1)
  151. #define cmeEDITOR_CLOSE    (cmVALID-2)
  152.  
  153. //EDITOR STANDARD DIALOG CODES
  154. #define edOUT_OF_MEMORY          0 //buffer can't grow up
  155. #define edREAD_ERROR             1 //can't read text
  156. #define edWRITE_ERROR            2 //can't write text
  157. #define edCREATE_ERROR           3 //can't create file
  158. #define edSAVE_MODIFY            4 //save? (yes, no, cancel)
  159. #define edSAVE_UNTITLED          5 //save untitled? (yes, no, cancel)
  160. #define edSAVE_AS                6 //save file as
  161. #define edFIND                   7 //find
  162. #define edSEARCH_FAILED          8 //search string not found
  163. #define edREPLACE                9 //search & replace
  164. #define edREPLACE_PROMPT        10 //replace this occurence? (yes, no, cancel)
  165. #define edGOTO_LINE             11 //goto line number
  166.  
  167. typedef void (*Teditors_supervisor) ( char *file_name, uint where, int bytes_inserted, int lines_inserted );
  168.  
  169. class Teditor;
  170.  
  171. class Ttext_editor
  172. {
  173. //<R> means read-only
  174. //<R/W> means read/write
  175.   public:
  176.     Teditor *editor; //<R> item that displays text editor on the screen
  177.     char *file_name; //<R> pointer to file name, or NULL
  178.     uint date, time; //<R> file's date and time of last modification
  179.     char assoc_number; //<R> number of items that dislay this text
  180.     char *edit_buffer; //<R> <text><cursor/gap><text>
  181.     uint buf_size; //<R> current size of the edit buffer
  182.     uint buf_len; //<R> number of characters in the edit buffer
  183.     uint gap_len; //<R> gap length
  184.     uint cur_ptr; //<R> cursor offset
  185.     uint sel_start; //<R> offset of the selection origin
  186.     uint sel_end; //<R> offset of the selection end
  187.     uint cur_pos_x; //<R> cursor x-pos
  188.     uint cur_pos_y; //<R> cursor y-pos
  189.     uint cur_after_eol; //<R> cursor is cur_after_eol columns after current line end
  190.     uint limit_xl; //<R> max length for the lines
  191.     uint limit_yl; //<R> current number of lines in the buffer
  192.     Tset valid_chars; //<R/W>
  193.     uint booleans;
  194. //constructor/destructor
  195.     Ttext_editor( uint _buf_size, Teditor *_editor );
  196.     Ttext_editor( char *_edit_buffer, uint _buf_size, Teditor *_editor );
  197.     virtual ~Ttext_editor( void );
  198. //buffer manipulations
  199.     boolean set_buf_size( uint new_size );
  200.     void set_buf_len( uint length ); //update gap after loading text at the end of the edit_buffer
  201. //cursor/selection
  202.     void set_cur_ptr( uint p, char select_mode );
  203.     void set_cur_xy( int _x, uint _y, char select_mode );
  204.     void set_select( uint new_start, uint new_end, int cur_start );
  205.     void hide_select( void );
  206.     boolean has_selection( void );
  207.     uint lines_selected( void );
  208. //undo works for changes sinse last cursor movement
  209.     void undo( void );
  210. //text insert - at the current cursor position, mark is overwriten
  211.     boolean insert_text( char *text, uint length, int select_text );
  212.     boolean insert_string( char *text, int select_text );
  213.     boolean insert_from( Ttext_editor *text_editor ); //insert selected text from another editor
  214.     int smart_tab( void );
  215.     void new_line( void ); //places a new line at the cursor
  216. //text deletion
  217.     void delete_select( void );
  218.     void delete_range( uint start_ptr, uint end_ptr, int del_select);
  219. //clipboard services
  220.     boolean clip_copy( void );
  221.     void clip_cut( void );
  222.     void clip_paste( void );
  223. //get text
  224.     void get_text( char *text, uint ofs, uint length );
  225.     void get_line_str( char *str, uint length );
  226.     void get_word_str( char *str, uint length );
  227. //browsing
  228.     uint next_char( uint p ); //offset of the next char for p
  229.     uint next_line( uint p ); //offset of the next line for p
  230.     uint next_word( uint p ); //offset of the next word for p
  231.     uint prev_char( uint p ); //offset of the prev char for p
  232.     uint prev_line( uint p ); //offset of the next line for p
  233.     uint prev_word( uint p ); //offset of the next word for p
  234.     uint line_start( uint p ); //line start for p
  235.     uint line_end( uint p ); //line end for p
  236.     uint line_move( uint p, int count ); //count - lines to move up/down
  237.     char buf_char( uint p ); //p-th character in the edit_buffer
  238.     uint buf_ptr( uint p ); //return the edit_buffer position of the p-th char
  239.     boolean search( char *find_str, uint options );
  240.     virtual void format_line( word *draw_buf, uint line_ptr, int width,
  241.                       char normal, char selected );
  242.     uint editor_dialog( int dialog, void *info );
  243. //file name/load/save
  244.     virtual void set_name( char *_file_name );
  245.     boolean load( void );
  246.     boolean save( void );
  247.  
  248.   protected:
  249.     uint del_count; //<R> used to undo deletions
  250.     uint ins_count; //<R> used to undo insertions
  251.     int char_pos( uint p, uint target ); //how many columns are between p and target
  252.     uint char_ptr( uint p, int target ); //move target columns to right
  253.     boolean insert_buffer( char *p, uint offset, uint length, int allow_undo, int select_text );
  254.     void clear_eol_spaces( void );
  255.     void start_select( void );
  256.     void update( uint cur_ptr_inserted, int bytes_inserted, int lines_inserted );
  257.  
  258.   friend class Teditor;
  259.   friend class Tfile_editor;
  260. };
  261.  
  262. #ifdef SYNTAXHILIGHT
  263. class Tsyntax_editor: public Ttext_editor
  264. {
  265.   public:
  266.     uint syntax_type;
  267.     Tsyntax_editor( uint _buf_size, Teditor *_editor );
  268.     Tsyntax_editor( char *_edit_buffer, uint _buf_size, Teditor *_editor );
  269.     virtual void set_name( char *_file_name );
  270.     virtual void format_line( word *draw_buf, uint line_ptr, int width, char normal, char selected );
  271. };
  272. #endif
  273.  
  274. class Teditor: public Titem
  275. {
  276. //<R> means read-only
  277. //<R/W> means read/write
  278.   public:
  279.     Titem *indicator;
  280.     uint delta_x; //<R> leftmost visible column
  281.     uint delta_y; //<R> topmost visible row
  282.     uint cur_ptr_svd;
  283.     uint cur_pos_x_svd;
  284.     uint cur_pos_y_svd;
  285.     uint marks[10]; //<R/W> used for marking current cursor position
  286.     Ttext_editor *text_editor;
  287.     Teditor( Ttext_editor *_text_editor, int _xl, int _yl );
  288.     virtual ~Teditor( void );
  289.     boolean cursor_visible( void );
  290.     void track_cursor( boolean center );
  291.     void scroll_to( int _x, int _y );
  292.     uint get_mouse_ptr( int local_x, int local_y );
  293.     void find( void );
  294.     void replace( void );
  295.  
  296.   protected:
  297.     uint draw_ptr;
  298.     uint draw_line;
  299.     virtual void get_focused( void );
  300.     virtual boolean release_focus( void );
  301.     virtual void calc_bounds( int delta_xl, int delta_yl );
  302.     virtual void draw( void );
  303.     virtual void event_handler( Tevent &ev );
  304.     virtual void convert_event( Tevent &ev );
  305.     virtual void update_commands( void );
  306.     virtual void update( uint cur_ptr_inserted, int bytes_inserted, int lines_inserted );
  307.     virtual uint editor_dialog( int dialog, void *info );
  308.     void do_search_replace( void );
  309.  
  310.   private:
  311.     void init( void );
  312.  
  313.   friend class Ttext_editor;
  314. };
  315.  
  316. class Tmemo: public Teditor
  317. {
  318.   public:
  319.     char *buffer;
  320.     Tmemo( char *_buffer, uint buf_size, int _xl, int _yl );
  321.  
  322.   protected:
  323.     virtual void ok_item( void );
  324. };
  325.  
  326. class Tfile_editor: public Teditor
  327. {
  328. //<R> means read-only
  329. //<R/W> means read/write
  330.   public:
  331.     Tfile_editor *next_editor; //<R> next file editor
  332.     Tfile_editor( char *_file_name, int _xl, int _yl );
  333.     virtual ~Tfile_editor( void );
  334.     virtual boolean valid( uint command );
  335.     boolean save( void );
  336.     boolean save_as( void );
  337.  
  338.   protected:
  339.     virtual void event_handler( Tevent &ev );
  340.     virtual void update_commands( void );
  341.     virtual void update( uint cur_ptr_inserted, int bytes_inserted, int lines_inserted );
  342.     virtual uint editor_dialog( int dialog, void *info );
  343.  
  344.   friend class Ttext_editor;
  345. };
  346.  
  347. struct Tedit_window_status
  348. {
  349.   int x;
  350.   int y;
  351.   int xl;
  352.   int yl;
  353.   uint state;
  354.   int icon_x;
  355.   int icon_y;
  356.   uint cur_pos_x;
  357.   uint cur_pos_y;
  358.   uint delta_x;
  359.   uint delta_y;
  360.   uint marks[10];
  361.   char file_name[_MAX_PATH];
  362. };
  363. #define TEDIT_WINDOW_STATUS_SIZE (sizeof(Tedit_window_status)-_MAX_PATH)
  364.  
  365. class Tedit_window: public Tfile_window
  366. {
  367.   public:
  368.     Tfile_editor *editor;
  369.     Tedit_window( char *fn, int _xl, int _yl );
  370.     virtual ~Tedit_window( void );
  371.     void save_status( Tedit_window_status &st );
  372.     void restore_status( Tedit_window_status &st );
  373.  
  374.   protected:
  375.     virtual void initialize( void );
  376. };
  377.  
  378. #endif //_PVEDITOR_H
  379.  
  380. #ifdef DECLARE_PVEDITOR
  381. Tset word_chars;
  382. uint editor_flags = efAUTO_INDENT + efBACKUP_FILES + efPROMPT_ON_REPLACE;
  383. uint tab_size = 8;
  384. char find_str[81] = "";
  385. char replace_str[81] = "";
  386. char *filter_str = NULL;
  387. Ttext_editor *clipboard = NULL;
  388. Ttext_editor *current_editor = NULL;
  389. Tfile_editor *open_editors = NULL;
  390. Teditors_supervisor editors_supervisor = NULL;
  391. #ifdef CPPHILIGHT
  392. char *cpp_hilight_extensions = NULL;
  393. char cpp_syntax_colors[16] = { 14,7,15,14,15,11,11,10 };
  394. #endif
  395. #ifdef ASMHILIGHT
  396. char *asm_hilight_extensions = NULL;
  397. char asm_syntax_colors[16] = { 14,7,15,14,15,11,11,10,13 };
  398. #endif
  399. #ifdef A51HILIGHT
  400. char *a51_hilight_extensions = NULL;
  401. char a51_syntax_colors[16] = { 14,7,15,14,15,11,11,10,13 };
  402. #endif
  403. #else
  404. extern Tset word_chars;
  405. extern uint editor_flags;
  406. extern uint tab_size;
  407. extern char find_str[81];
  408. extern char replace_str[81];
  409. extern char *filter_str;
  410. extern Ttext_editor *clipboard;
  411. extern Ttext_editor *current_editor;
  412. extern Tfile_editor *open_editors;
  413. extern Teditors_supervisor editors_supervisor;
  414. #ifdef CPPHILIGHT
  415. extern char *cpp_hilight_extensions;
  416. extern char cpp_syntax_colors[16];
  417. #endif
  418. #ifdef ASMHILIGHT
  419. extern char *asm_hilight_extensions;
  420. extern char asm_syntax_colors[16];
  421. #endif
  422. #ifdef A51HILIGHT
  423. extern char *a51_hilight_extensions;
  424. extern char a51_syntax_colors[16];
  425. #endif
  426. #endif
  427.  
  428. Tmemo *memo( char *title, char *buffer, uint buf_size, int _xl, int _yl );
  429. Tedit_window *edit_file( char *fn );
  430. Tedit_window *open_file( char *fn );
  431. Tedit_window *open_file( Tedit_window_status &st );
  432. void show_clipboard( void );
  433.